
<template>
    <rx-dialog @ok="handleSubmit" @cancel="cancel">
        <a-form ref="form" :model="mdl" :rules="rules">
            <a-form-item style="display:none;">
                <a-input v-model:value="mdl.receiptUserId"/>
                <a-input v-model:value="mdl.receiptUserNo"/>
            </a-form-item>
            <a-row>
              <a-col :span="24">
                <a-form-item :label="i18n('form.transferee','移交人')">
                  <span>{{deliverUserName}}</span>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="24">
                <a-form-item name="receiptUserNameValid" :label="i18n('form.receiver','接管人')">
                  <a-input-group compact style="display: flex;margin-top: 6px;">
                    <a-input readOnly v-model:value="mdl.receiptUserNameValid" style="flex: 1;"/>
                    <a-button @click="joinUser(2)"  style="width: 50px">·&nbsp;·&nbsp;·</a-button>
                  </a-input-group>
                </a-form-item>
              </a-col>
            </a-row>
        </a-form>
    </rx-dialog>
</template>
<script>
    import { BaseFormModel,RxDialog } from "@lowcode/jpaas-base-lib"
    import { ShareDialog } from '@lowcode/jpaas-share-component'
    import BpmDeliverApi from '@/common/api/bpm/bpmDeliver'

    export default {
        name: 'BpmQuitUserDeliver',
        mixins:[BaseFormModel],
        components: {
            RxDialog,
        },
        props: {
            deliverUserId: {
                type: String,
                required: false,
                default: null
            },
            deliverUserNo: {
                type: String,
                required: false,
                default: null
            },
            deliverUserName: {
                type: String,
                required: false,
                default: null
            },
        },
        data() {
            return {
                rules: {
                  receiptUserNameValid: [{required: true, message: "请选择接管人", trigger: 'change'}],
                },
                id:'',
                receiptUserId:'',
                receiptUserNo:'',
                receiptUserName:''
            }
        },
        created(){
            this.getByDeliverUserId(this.deliverUserId);
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "bpmDeliver", key);
            },
            getByDeliverUserId(deliverUserId){
                var self = this;
                BpmDeliverApi.getByDeliverUserId({deliverUserId : deliverUserId}).then(res => {
                    if (res) {
                        Object.assign(self.mdl,{receiptUserNameValid:res.receiptUserName})
                        this.id = res.id;
                        this.receiptUserId = res.receiptUserId;
                        this.receiptUserNo = res.receiptUserNo;
                        this.receiptUserName = res.receiptUserName;
                    }
                });
            },
            validForm(values){
                if(this.deliverUserId == this.receiptUserId){
                    this.$message.error(this.i18n('notSame','移交人和接管人不能选择同一个人！'));
                    return false;
                }

                values.id = this.id;
                values.deliverUserId = this.deliverUserId;
                values.deliverUserNo = this.deliverUserNo;
                values.deliverUserName = this.deliverUserName;
                values.receiptUserId = this.receiptUserId;
                values.receiptUserNo = this.receiptUserNo;
                values.receiptUserName = this.receiptUserName;

                return true;
            },

            save(values){
                return BpmDeliverApi.save(values);
            },

            joinUser(){
                let self = this;
                ShareDialog.openUserDialog({
                    curVm: this,data:{single:true}, widthHeight: ['800px', '600px']
                },function(user){
                    if(user==null) {
                        self.$message.error(this.i18n('noSelect','未选择用户！'));
                        return;
                    }
                    Object.assign(self.mdl,{receiptUserNameValid:user.fullName})
                    self.receiptUserId = user.userId;
                    self.receiptUserNo = user.userNo;
                    self.receiptUserName = user.fullName;

                })
            },

        }
    }
</script>
<style>
    .relick a{
        margin-right: 10px;
    }

</style>
